package com.dayuanit.dy15.lesson22.demo1;

public class TestSort {

    public static void main(String[] args) {
        //算法：排序 查找
        //数据结构 + 算法 = 程序

        //排序：冒泡 选择 插入 希尔 堆排序 归并排序 快速排序

        int a = 5;
        int b = 6;

        int tmp = a;

        //此时b已经将a的值覆盖掉了，再也找不到了，也就没法将a的值赋值给b了。
        a = b;
        b = tmp;

        System.out.println("a=" + a);
        System.out.println("b=" + b);

//        a = 6;
//        b = 5;

        int[] nums = {2, 1, 9, 5, 5, 3};

        for (int i=0; i<nums.length - 1; i++) {
            for (int j=0; j<nums.length - i - 1; j++) {
                //从小到大
                if (nums[j] > nums[j + 1]) {
                    //交换位置
                    int temp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = temp;
                }
            }
        }

        for (int num : nums) {
            System.out.print(num);
        }

        //1 2 9 5 5 3
        //1 2 9 5 5 3
        //1 2 5 9 5 3
        //1 2 5 5 9 3
        //1 2 5 5 3 9

        //1 2 5 5 3 9
        //1 2 5 5 3 9
        //1 2 5 5 3 9
        //1 2 5 3 5 9

        //1 2 5 3 5 9
        //1 2 5 3 5 9
        //1 2 3 5 5 9

        //1 2 3 5 5 9
        //1 2 3 5 5 9

        //1 2 3 5 5 9

    }
}
